package com.ax.base.common.controller;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ax.base.common.domain.BaseHint;
import com.ax.base.common.service.BaseHintService;
import com.ax.base.common.utils.AjaxRes;
import com.ax.base.common.utils.Const;

@Controller
@RequestMapping("/sys/baseHint")
public class BaseHintController {
	@Autowired
	BaseHintService baseHintService;
	/**
	 * 菜单页面的跳转
	 */
	@GetMapping("")
	String pharmacist(Model model) {
		return "common/basehint/basehint";
	}
	
	/**
     * 查询所有提示
     *
     * @param Map<String, Object> map
     *
     * @return List<BaseHint>
     */
    @RequestMapping("queryBaseHint")
    @ResponseBody
    public List<BaseHint> queryBaseHint(@RequestParam Map<String, Object> params){
    	 List<BaseHint> baseHints = baseHintService.queryBaseHintSer(params);
    	 return baseHints;
    }
	
    /**
	 * 提示配置详情(新增)
	 * 
	 * @param  无
	 *           
	 * @return HTML
	 */
	@GetMapping("/add")
	String add(Model model) {
		return "common/basehint/add";
	}
	
	/**
	 * 提示配置详情(修改)
	 * 
	 * @param Long id
	 *           
	 * @return BaseHint baseHints
	 */
	@GetMapping("/edit/{id}")
	String edit(Model model,@PathVariable("id") Long id) {
		model.addAttribute("basehint",baseHintService.getBaseHint(id));
		return "common/basehint/edit";
	}
	
	/**
     * 添加配置详情
     * 
     * @param BaseHint baseHint
     * 
     * @return SUCC
     */
    @RequestMapping("insertBaseHint")
    @ResponseBody
    public AjaxRes insertBaseHint(AjaxRes ajaxRes,BaseHint baseHint){
        try{
            this.baseHintService.insertBaseHintSer(baseHint);
            ajaxRes.setSucceed(Const.SAVE_SUCCEED);
        }catch(Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
    
    /**
     * 修改配置详情
     * 
     * @param BaseHint baseHint
     * 
     * @return SUCC
     */
    @RequestMapping("updateBaseHint")
    @ResponseBody
    public AjaxRes updateBaseHint(AjaxRes ajaxRes,BaseHint baseHint){
        try{
            this.baseHintService.updateBaseHintSer(baseHint);
            ajaxRes.setSucceed(Const.UPDATE_SUCCEED);
        }catch(Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
}
